import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import divider from './components/divider'
import title from './components/title'
import ad from './components/ad'
import list from './components/list'
import button from './components/button.vue'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import FastClick from 'fastclick'
import './plugins/vant'
import 'normalize.css/normalize.css'
import './assets/style/font.css'
import './assets/style/main.css'

import 'amfe-flexible'
import * as filters from './utils/filter' // global filters

if ('addEventListener' in document) {
  document.addEventListener('DOMContentLoaded', function() {
    FastClick.attach(document.body)
  }, false)
}

Vue.config.productionTip = false

Vue.component(divider.name, divider)
Vue.component(title.name, title)
Vue.component(ad.name, ad)
Vue.component(list.name, list)
Vue.component(button.name, button)

import '../mock'

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  NProgress.start()
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

router.afterEach(() => {
  // 进度条消失
  NProgress.done()
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
